<?php
class BaiDuProductSvc extends BaiDuCommon
{
    /*
        添加商品信息
        params
            shop_id 商户唯一id
            upc 商品条形码
            name 商品名称
            status 商品状态 1-上架 0-下架
            desc 商品描述
            sale_price 销售价格 单位：分

            photos[] 图片数组对象(photo)
    */
    public function addProduct($shop_id = '', $upc = '', $name = '', $status = 0, $desc = '', $sale_price = 0, $photos = array())
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['upc'] = $upc; //UPC码    
        $data['name'] = $name; //UPC名称    
        $data['status'] = $status; //商品状态    
        $data['cat1_id'] = "1445361564"; //一级分类ID    
        $data['cat2_id'] = "1445361565"; //二级分类ID    
        $data['cat3_id'] = "1445361566"; //三级分类ID    
        $data['brand_id'] = "1514625907"; //品牌ID 常般药品    
        $data['desc'] = $desc; //简介描述    
        $data['left_num'] = 0; //库存数量    
        $data['sale_price'] = $sale_price; //销售价格
        $data['market_price'] = $sale_price; //市场价格

        $data['photos'] = $photos; //商品图片        

        return $data;
    }

    /*
        请求添加商品信息
        params
            data 添加商品信息对象(addProduct)
    */
    public function sendAddProduct($data = array())
    {
        $cmd = "sku.create";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("add_product : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("add_product_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        更新商品信息
        params
            shop_id 商户唯一id
            sku_id 百度商品ID
            name 商品名称
            status 商品状态 1-上架 0-下架
            desc 商品描述
            sale_price 销售价格 单位：分

            photos[] 图片数组对象(photo)
    */
    public function updateProduct($shop_id = '', $sku_id = 0, $name = '', $status = 0, $desc = '', $sale_price = 0, $photos = array())
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['sku_id'] = $sku_id; //百度商品ID    
        $data['name'] = $name; //UPC名称    
        $data['status'] = $status; //商品状态    
        $data['brand_id'] = "1514625907"; //品牌ID 常般药品    
        $data['desc'] = $desc; //简介描述    
        $data['left_num'] = 0; //库存数量    
        $data['sale_price'] = $sale_price; //销售价格
        $data['market_price'] = $sale_price; //市场价格

        $data['photos'] = $photos; //商品图片        

        return $data;
    }

    /*
        请求更新商品信息
        params
            data 更新商品信息对象(updateProduct)
    */
    public function sendUpdateProduct($data = array())
    {
        $cmd = "sku.update";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("update_product : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("update_product_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        上线商品信息
        params
            shop_id 商户唯一id
            sku_id 商品id "654321,123456"; 最多支持100个SKU同时上线
    */
    public function onlineProduct($shop_id = '', $sku_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['sku_id'] = $sku_id;

        return $data;
    }

    /*
        请求上线商品信息
        params
            data 上线商品信息对象(onlineProduct)
    */
    public function sendOnlineProduct($data = array())
    {
        $cmd = "sku.online";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("online_product : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("online_product_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }


    /*
        下线商品信息
        params
            shop_id 商户唯一id
            sku_id 商品id "654321,123456"; 最多支持100个SKU同时上线
    */
    public function offlineProduct($shop_id = '', $sku_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['sku_id'] = $sku_id;

        return $data;
    }

    /*
        请求下线商品信息
        params
            data 上线商品信息对象(offlineProduct)
    */
    public function sendOfflineProduct($data = array())
    {
        $cmd = "sku.offline";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("offline_product : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("offline_product_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        获取品牌列表
        params
            keyword 查询关键字
    */
    public function brandList($keyword = '')
    {
        $data = array();
        $data['keyword'] = $keyword;

        return $data;
    }

    /*
        请求获取品牌列表
        params
            data 获取品牌列表对象(brandList)
    */
    public function sendBrandList($data = array())
    {
        $cmd = "sku.brand.list";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("get_brand_list : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("get_brand_list_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        批量修改库存信息
        params
            shop_id 商户唯一id
            skuid_stocks skuid对应库存 6930463400823:10;6930463400823:100 最多支持100个SKU同时修改
    */
    public function updateStockBatch($shop_id = '', $skuid_stocks = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['skuid_stocks'] = $skuid_stocks;

        return $data;
    }


    /*
        请求批量修改库存信息
        params
            data 批量修改库存信息(updateStockBatch)
    */
    public function sendUpdateStockBatch($data = array())
    {
        $cmd = "sku.stock.update.batch";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("update_stock : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("update_stock_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        批量修改商品价格信息
        params
            shop_id 商户唯一id
            skuid_price skuid对应价格 6930463400823:10;6930463400823:100 最多支持100个SKU同时修改
    */
    public function updatePriceBatch($shop_id = '', $skuid_price = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['skuid_price'] = $skuid_price;

        return $data;
    }

    /*
        请求修改商品价格信息
        params
            data 批量修改价格信息(updatePriceBatch)
    */
    public function sendUpdatePriceBatch($data = array())
    {
        $cmd = "sku.price.update.batch";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("update_price : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("update_price_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        获取商品列表
        params
            shop_id 商户唯一id
            page 页码
            page_size 每页数量 1-100
    */
    public function productList($shop_id = '', $page = '', $page_size = 100)
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['page'] = $page;
        $data['pagesize'] = $page_size;

        return $data;
    }

    /*
        请求获取商品列表
        params
            data 获取商品列表对象(productList)
    */
    public function sendProductList($data = array())
    {
        $cmd = "sku.list";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("product_list : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("product_list_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        绑定商品自定义分类id
        params
            shop_id 商户唯一id
            sku_id 商品id
            category_id 分类id串 多个用半角“,”隔开，为空时，表示删除商品所有关系
    */
    public function bindCategory($shop_id = '', $sku_id = 0, $category_id = 0)
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['sku_id'] = $sku_id;
        $data['category_id'] = $category_id;

        return $data;
    }

    /*
        请求绑定商品自定义分类id
        params
            data 绑定商品自定义分类对象(bindCategory)
    */
    public function sendBindCategory($data = array())
    {
        $cmd = "sku.shop.category.map";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("bind_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("bind_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        创建图片对象
        params
            url 图片地址
            is_master 是否首图
    */
    public function createPhoto($url = '', $is_master = 0)
    {
        $data = array();
        $data['url'] = $url;
        $data['is_master'] = $is_master;

        return $data;
    }
}
?>